

<div class="layui-form" lay-filter="layuiadmin-form-role" id="form">
	<div class="form-cont">
		<div class="layui-form-item verify">
		  <label class="layui-form-label">用户名</label>
		  <div class="layui-input-block">
			  <input type="text" autocomplete="off" v-model="detail.admin_name" :disabled="type==1?false:true" verify='require|username' placeholder="请输入用户名" class="layui-input">
			  <span class="hint">请输入用户名</span>
			</div>
		</div>
		<div class="layui-form-item verify" v-if="type!=3">
		  <label class="layui-form-label">密码</label>
		  <div class="layui-input-block">
			  <input type="text" autocomplete="off" v-model="detail.pwd" :verify='type==1?"require|pass":"pass"' :placeholder="type==1?'请输入密码':'修改密码'" class="layui-input">
			  <span class="hint">请输入密码</span>
			</div>
		</div>
		<div class="layui-form-item verify">
		  <label class="layui-form-label">角色</label>
		  <div class="layui-input-block">
		      <div class="layui-unselect layui-form-select">
		      	<div class="layui-select-title"><input type="text" name='jrole' @click="roleList" :data='detail.role_id' verify='require' placeholder="请选择角色" class="layui-input layui-unselect" readonly><i
		      		 class="layui-edge"></i></div>
		      	<dl class="layui-anim layui-anim-upbit">
		      		<dd class="layui-select-tips layui-this">请选择角色</dd>
		      		<dd :data='x.role_id' v-for="(x,index) in role" v-if="x.role_status==1">{{x.role_name}}</dd>
		      	</dl>
		      </div>
			  <span class="hint">请选择角色</span>
		  </div>
		</div>
		<div class="layui-form-item verify">
		  <label class="layui-form-label">姓名</label>
		  <div class="layui-input-block">
			  <input type="text" v-model="detail.real_name" verify='require|realname' placeholder="请输入姓名" class="layui-input">
			  <span class="hint">请输入真实姓名</span>
			</div>
		</div>
		<div class="layui-form-item verify">
		  <label class="layui-form-label">性别</label>
		  <div class="layui-input-block">
		      <div class="layui-unselect layui-form-select">
		      	<div class="layui-select-title"><input type="text" name='sex' :data='detail.sex' placeholder="请选择性别" class="layui-input layui-unselect" disabled><i
		      		 class="layui-edge"></i></div>
		      	<dl class="layui-anim layui-anim-upbit">
		      		<dd class="layui-select-tips layui-this">请选择性别</dd>
		      		<dd data='0'>保密</dd>
						<dd data='1'>男</dd>
						<dd data='2'>女</dd>
		      	</dl>
		      </div>
		  </div>
		</div>
		<div class="layui-form-item verify">
		  <label class="layui-form-label">电话</label>
		  <div class="layui-input-block">
			  <input type="text" v-model="detail.tel" verify='phone' placeholder="请输入电话" class="layui-input">
			  <span class="hint">请输入电话</span>
			</div>
		</div>
		<div class="layui-form-item verify">
		  <label class="layui-form-label">邮箱</label>
		  <div class="layui-input-block">
			  <input type="text" v-model="detail.email" verify='email' placeholder="请输入邮箱" class="layui-input">
			  <span class="hint">请输入邮箱</span>
			</div>
		</div>
		<div class="layui-form-item">
		  <label class="layui-form-label">状态</label>
		  <div class="layui-input-block">
		      <div class="layui-unselect layui-form-switch" :class="{'layui-form-onswitch':detail.status==1}" lay-skin="_switch" @click="radioF()"><em>{{detail.status==1?'启用':'停用'}}</em><i></i></div>
		  </div>
		</div>
	</div>
  <div class="form-btn" v-if="type!=3">
      <input type="button" value="保存" class="layui-btn" @click="submit">
  </div>
</div>
<style type="text/css">
	
</style>
<script>
	layui.use(['form'], function(){
	  var $ = layui.$
	  ,form = layui.form;
	  form.verify(layui.admin.verify);
	  var forms=new Vue({
	  		el:'#form',
	  		data:{
	  			role:'',
				type:layui.admin.objData.type,
				detail:{
					status:1,
					sex:'',
					role_id:''
				},
				old_detail:{},
				role_name:'',
				sex:''
	  		},
	  		mounted:function() {
				//初始化
				var _this=this;
	  			if(this.type!=1) this.detail=layui.admin.objData.detail,this.old_detail=JSON.stringify(layui.admin.objData.detail);
				
				if(this.detail.sex==1){
					this.sex='男';
				}else if(this.detail.sex==2){
					this.sex='女';
				}else if(this.detail.sex===0){
					this.sex='保密';
				}
				$('input[name="jrole"]').val(this.detail.role_name);
				$('input[name="sex"]').val(this.sex);
	  		},
	  		methods:{
	  			radioF:function(){//radio选择
	  				this.detail.status==1?this.detail.status=2:this.detail.status=1;
	  			},
				submit:function(){
					if(layui.admin.form('#form')){
						this.detail.role_id=parseInt($('input[name="jrole"]').attr('data'));
						this.detail.sex=parseInt($('input[name="sex"]').attr('data'));
						if(this.type==2){   //编辑
							var data=layui.admin.filter(this.detail,JSON.parse(this.old_detail),'admin_id');
							if(data){
								layui.admin.formapi('admins/update',data);
							}
						}else{  //添加
							layui.admin.formapi('admins/add',this.detail);
						}
					}
				},
				roleList:function(){
					var _this=this;
					if(!this.role){
						layui.admin.ajax('role/list',{},1).then(function(res){
							_this.role=res.data.list;
						});
					}
				}
	  		}
	  	})
	});
</script>
